package com.chebaohui.iqs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.ResultCode;
import com.chebaohui.iqs.entity.*;
import com.chebaohui.iqs.entity.req.*;
import com.chebaohui.iqs.entity.res.*;
import com.chebaohui.iqs.service.CheckService;
import com.chebaohui.iqs.sign.SignParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * describe:控制层:查询
 * 
 * @author regas_xie
 *
 */
@Api(value = "check", description = "查询接口", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping(value = "check")
public class CompanyCheckController {
	/**
	 * log:日志输出
	 */
	private Log log = LogFactory.getLog(CompanyCheckController.class);

	@Autowired
	private CheckService checkService;

	@ApiOperation(value = "往年保单查询", httpMethod = "POST", notes = "根据车牌号 或者 车架号与发动机号进行查询")
	@RequestMapping(value = "/policy/lastyear", method = RequestMethod.POST)
	public Result<LastYearPolicyRes> checkCar(
			@ApiParam(value = "往年保单查询请求参数", required = true) @RequestBody(required = true) Paramter<LastYearPolicyReq> param) {
		Result<LastYearPolicyRes> result = null;
		
		if (!SignParam.decrypted(param.getSign()))
			result = new Result<>(ResultCode.L01);
		else
			result = checkService.lastPolicy(param);

		log.info("往年保单查询:" + "\n" + "请求参数：" + JSONObject.toJSONString(param) + "\n" + "返回结果："
				+ JSONObject.toJSONString(result));
		return result;
	}
}
